package com.wondream.dao;

import com.wondream.domain.Article;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Collection;
import java.util.List;

/**
 * @author wondream
 * @version 1.0
 * @create 2022/5/12 9:56 PM
 */
public interface ArticleJpqlDao extends JpaRepository<Article, Integer>, JpaSpecificationExecutor<Article> {
    //展示位置参数绑定
    @Query("from Article a where a.author=?1 and a.title=?2")
    List<Article> findByCondition1(String author, String title);

    //展示名字参数绑定
    @Query("from Article a where a.author=:author and a.title=:title")
    List<Article> findByCondition2(@Param("author") String author,
                                    @Param("title") String title);

    //展示like模糊查询
    @Query("from Article a where a.title like %:title%")
    List<Article> findByCondition3(@Param("title") String title);

    //展示排序查询
    @Query("from Article a where a.title like %:title% order by aid desc")
    List<Article> findByCondition4(@Param("title") String title);

    //展示分页查询
    @Query("from Article a where a.title like %:title% ")
    Page<Article> findByCondition5(Pageable pageable, @Param("title") String title);

    //展示传入集合参数查询
    @Query("from Article a where a.aid in :aids")
    List<Article> findByCondition6(@Param("aids") Collection<Integer> aids);

    //展示传入Bean进行查询
    @Query("from Article a where a.author=:#{#article.author} and a.title=:#{#article.title}")
    List<Article> findByCondition7(@Param("article") Article article);
}
